<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>common/ui/jquery-easyui-1.3.0/themes/default/easyui.css">
		<script type="text/javascript"
			src="<%=basePath%>common/ui/jquery-easyui-1.3.0/jquery-1.7.2.min.js"></script>
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>common/ui/jquery-easyui-1.3.0/themes/icon.css">
		<script type="text/javascript"
			src="<%=basePath%>common/ui/jquery-easyui-1.3.0/jquery.easyui.min.js"></script>
		<script type="text/javascript">  
var tree;
var dlg_Edit;
var dlg_Edit_form;

  $(function(){  
  
  dlg_Edit = $('#Dlg-Edit').dialog({
        closed: true,
        modal: true,
        toolbar: [{
            text: '保存',
            iconCls: 'icon-save',
            handler: saveData
        }, '-', {
            text: '关闭',
            iconCls: 'icon-no',
            handler: function () {
                dlg_Edit.dialog('close');
            }
        }]
    });
    
    dlg_Edit_form = dlg_Edit.find('form'); 
    
    tree=$('#tree').tree({     
        url: '<%=basePath%>manage/admin/product_categories!dataList.action',
        checkbox:true,
        
         });  
      
 });   
 
 function add() {
    dlg_Edit.dialog('open');
    dlg_Edit_form.form('clear');
    dlg_Edit_form.url = '<%=basePath%>manage/admin/product_categories!preservation.action';
}
function saveData() {
    dlg_Edit_form.form('submit', {
        url: dlg_Edit_form.url,
        onSubmit: function () {
            return $(this).form('validate');
        },
        success: function (data) {
            //alert(data);
            eval('data=' + data);
            if (data.success) {
                dlg_Edit.dialog('close');
                 $('#tree').tree('reload');  
            } else {
                $.messager.alert('错误', data.msg, 'error');
            }
        }
    });
}
function getSelectedArr() {
    var ids = [];
    var rows = grid.datagrid('getSelections');
    for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].ID);
    }
    return ids;
}
function getChecked(){
            var ids = [];
			var nodes = $('#tree').tree('getChecked');
			for(var i=0; i<nodes.length; i++){
				ids.push(nodes[i].text);
			}
			return ids;
		}
function arr2str(arr) {
    return arr.join(',');
}
function del() {
    var arr = getChecked();
    if (arr.length > 0) {
        $.messager.confirm('提示信息', '您确认要删除['+arr2str(arr)+']吗?', function (data) {
            if (data) {
                $.ajax({
                    url: '<%=basePath%>manage/admin/product_categories!remove.action?names=' + arr2str(arr),
                    type: 'GET',
                    timeout: 1000,
                    error: function () {
                        $.messager.alert('错误', '删除失败!', 'error');
                    },
                    success: function (data) {
                        eval('data=' + data);
                        if (data.success) {
                            $('#tree').tree('reload');  
                        } else {
                            $.messager.alert('错误', data.msg, 'error');
                        }
                    }
                });
            }
        });
    } else {
        Msgshow('请先选择要删除的记录。');
    }
}
    </script>

	</head>

	<body class="easyui-layout">
	  <div region="west" split="true" title="产品分类" style="width: 280px;" id="west">
         <div style="background: #C9EDCC; width: 100%;">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconcls="icon-add" onclick="add()" plain="true">添加</a>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconcls="icon-edit" onclick="edituser()" plain="true">修改</a>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconcls="icon-remove" onclick="del()"  plain="true">删除</a>
			</div>
			<ul id="tree"></ul>
      </div>
	
		<div data-options="region:'center',title:'产品类型信息'">
		  
		</div>

		<div id="Dlg-Edit" title="编辑窗口" style="width: 400px; height: 250px;">
			<div style="padding: 20px 20px 40px 80px;">
				<form method="post">
					<table>
						<tr>
							<td>
								分类：
							</td>
							<td>
								<select class="easyui-combotree" url="<%=basePath%>manage/admin/product_categories!dataList.action"
									name="parent" style="width: 204px;" />
							</td>
						</tr>
						<tr>
							<td>
								名称：
							</td>
							<td>
								<input name="title" class="easyui-validatebox" required="true"
									style="width: 200px;" />
							</td>
						</tr>
						<tr>
							<td>
								描述：
							</td>
							<td>
							   <textarea name="description" style="height:60px;width: 200px;">
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</body>
</html>
